
var MenuList = new Array();

$(function () {

    // 获取JSON文件的菜单栏列表数据
    var tokenData = NetUtils.TokenData();
    NetUtils.RequestJson(Api.Api_Menu_MenuList, tokenData, function(res){
        // res = res.data;
        MenuList = res;
        console.log('hello');

        res.forEach(function(item, index){
            var isCurClass = '';
            if(item.isCur) {

                isCurClass = 'cur disHover';
                showSubMenu(item);

            }

            $(".Top-LayOut .Top-LayOut-NavLeft").append('<li class="' + isCurClass +'" data-id="' + item.id + '"><a href="javascript:void(0);"><i class="fa ' + item.icon + '"></i> ' + item.name + '</a></li>');

        });

    }, function(){});




    $(".Top-LayOut .Top-LayOut-NavLeft > li").hover(function(){

        if(!$(this).hasClass("disHover")) {

            $(this).toggleClass("cur");

        }

    });

    // 点击顶部菜单总菜单栏显示对应的子菜单
    $(".Top-LayOut .Top-LayOut-NavLeft").on('click', 'li', function(){

        var id = $(this).data("id") - 1;

        $(this).addClass("cur disHover").siblings().removeClass("cur disHover");

        showSubMenu(MenuList[id]);

    });

    // 点击左侧菜单栏添加新的选项卡
    $(".West-Layout .West-Layout-LeftMenu .West-Layout-LeftMenu-List").on('click', 'li > a', function(){

        var TabName = $(this).text();

        var TabUrl = $(this).data("url");

        TabsUtils.openTab("#TabsContent", TabName, TabUrl, false, true);

    });

    $(".Top-LayOut-NavRight-Logout").on('click', function () {

        console.log('hello');
    });

});

/**
 * 显示子菜单列表
 * @param Data      @子菜单列表数据
 */
function showSubMenu(Data){

    var MenuListHTML = '';

    $(".West-Layout .West-Layout-LeftMenu .West-Layout-LeftMenu-Title").html(Data.name);

    Data.children.forEach(function(item){

        MenuListHTML += '<li><a href="javascript:void(0);" data-url="' + item.url + '"><i class="fa ' + item.icon + '"></i>' + item.name + '</a></li>';

    });

    $(".West-Layout .West-Layout-LeftMenu .West-Layout-LeftMenu-List").html(MenuListHTML);

}
